package com.example.springboot.mapper;

import com.example.springboot.entity.announcements;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AmaMangerMapper {

    @Select("select * from announcements")
    List<announcements> findAll();

    @Insert("INSERT INTO announcements (title, content,posted_by) " +
            "VALUES (#{title}, #{content},#{posted_by})")
    void addAnnouncement(announcements announcement);

    @Update("update announcements set title=#{title}, content=#{content} where announcement_id=#{announcement_id}")
    void editAnnouncement(announcements announcement);

    @Delete("DELETE FROM announcements WHERE announcement_id=#{announcement_id}")
    void deleteAnnouncement(int announcement_id);

    @Delete({
            "<script>",
            "DELETE FROM announcements WHERE announcement_id IN ",
            "<foreach item='announcement_id' collection='list' open='(' separator=',' close=')'>#{announcement_id}</foreach>",
            "</script>"
    })
    void deleteAnnouncementBatch(List<Long> ids);

    @Select("select * from announcements where title LIKE CONCAT('%', #{title}, '%') ")
    List<announcements> selectByTitle(String title);
}
